package app.v1.wdt.service.impl;

import app.common.utils.WdtUtils;
import app.common.utils.cjt.ao.SettingShopQueryShopAo;
import app.v1.wdt.domain.pojo.WdtShopGroup;
import app.v1.wdt.mapper.WdtShopGroupMapper;
import app.v1.wdt.service.WdtShopGroupService;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

/**
 * @author feizns
 * @since 2023/7/20
 */
@Service
@RequiredArgsConstructor
public class WdtShopGroupServiceImpl implements WdtShopGroupService {

    /**
     * 映射器
     */
    private final WdtShopGroupMapper mapper;

    /**
     * 汽车卖到商店
     */
    @Scheduled(cron = "0 */6 * * * ?")
    @Override
    public void autoFetchShopGroups() {
        try {
            WdtUtils.fetchSettingShopQueryShop(new SettingShopQueryShopAo(), detail -> {
                WdtShopGroup shop = mapper.getByShopNo(detail.getShop_no());
                if ( shop == null )
                    shop = new WdtShopGroup();
                shop.setShopNo(detail.getShop_no());
                shop.setShopName(detail.getShop_name());
                shop.setGroupId(detail.getGroup_id());
                shop.insertOrUpdate();
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
